#!/usr/bin/env bash
#
#
. ./base.sh
which mysqldump || ln -s /usr/local/mysql/bin/mysqldump /usr/local/bin/mysqldump
which mysql || ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
bash /server/scripts/php4_manage.sh stop
bash /home/scripts/update_v40/update_4.0.sh
chkconfig --add vod_api
chkconfig --add vod_node
chkconfig vod_api on
chkconfig vod_node on
#cd /home/vod_v38_stable/ && mysql -f <./bestarmedia_node_init.sql && mysql <./bestarmedia_node_update.sql
php /home/vod_v38_stable/migration/insert_profile.php
#php /home/vod_v38_stable/migration/insert_room.php
mysql -e "UPDATE bestarmedia_node.node_room s1,BX_VOD.TB_KTVNetRoom s2 SET s1.ktv_room_code=s2.KTVRoomCode WHERE s1.room_code=s2.RoomCode"
sleep 3
/etc/init.d/vod_api restart
/etc/init.d/vod_node restart
#
########################old service remove######################################
ps axj |egrep "2ktv|cloud|Wor" | grep -v "grep" | awk '{print $2}' |xargs kill -9
ps axj |grep vod_s |grep -v grep |awk '{print $2}' |xargs kill -9
\rm -f /server/scripts/php4_manage.sh
sed -i '/check_/d' /var/spool/cron/root
sed -i '/listen/d' /var/spool/cron/root
sed -i '/extra_script/d' /var/spool/cron/root
sed -i '/vod_s-/d' /var/spool/cron/root
sed -i '/auto_/d' /var/spool/cron/root
sed -i '/lacksong.php/d' /var/spool/cron/root
sed -i '/playdata.php/d' /var/spool/cron/root
sed -i '/batelog.php/d' /var/spool/cron/root
sed -i '/com_mysqlfile36.sh/d' /var/spool/cron/root
sed -i '/salt-minion/d' /var/spool/cron/root
sed -i '/guard/d' /var/spool/cron/root
sed -i '/cloud/d' /var/spool/cron/root
sed -i '/202.120.2.101/d' /var/spool/cron/root
sed -i '/delete.sh/d' /var/spool/cron/root
sed -i '/dbrsync/d' /var/spool/cron/root
sed -i '/php4_manage.sh/d' /var/spool/cron/root
sed -i '/repair.sh/d' /var/spool/cron/root
sed -i '/com_mysqlfile36.sh/d' /etc/rc.local
sed -i '/php4_manage.sh/d' /etc/rc.local
sed -i '/supervisord/d' /etc/rc.local
sed -i '/cloud/d' /etc/rc.local
sed -ri '/^mount/d' /etc/rc.local
sed -ri '/^sleep/d' /etc/rc.local
sed -i '/salt/d' /etc/hosts
sed -i '/local.mysql/d' /etc/hosts
sed -i '/zabbix/d' /etc/hosts
sed -i '/cms.beidousat.com/d' /etc/hosts
grep "redis-server" /etc/rc.local || echo "redis-server /usr/local/src/redis-2.8.5/redis.conf" >> /etc/rc.local
chkconfig netdata off
chkconfig salt-minion off


src_fn="/update/scripts/hold_up_v4/origin.sh"
dest_fn="/server/scripts/origin.sh"
down_stat=`http_download $src_fn $dest_fn`
[ $down_stat -eq 0 ] && printf_c "download $src_fn finish" || \
printf_c "download $sec_fn failed" $err_c
#>/server/scripts/version.idx
sed -i '/0$/d' /server/scripts/version.idx

src_fn="/update/4.0test/keep_run.sh"
dest_fn="/server/scripts/keep_run.sh"
down_stat=`http_download $src_fn $dest_fn`
[ $down_stat -eq 0 ] && printf_c "download $src_fn finish" || \
printf_c "download $sec_fn failed" $err_c

src_fn="/update/4.0test/vod_opt.sh"
dest_fn="/server/scripts/vod_opt.sh"
down_stat=`http_download $src_fn $dest_fn`
[ $down_stat -eq 0 ] && printf_c "download $src_fn finish" || \
printf_c "download $sec_fn failed" $err_c

grep "keep_run.sh" /var/spool/cron/root || echo "*/5 * * * * bash /server/scripts/keep_run.sh >/dev/null" >> /var/spool/cron/root
grep "vod_opt.sh" /var/spool/cron/root || echo "0 8 * * * bash /server/scripts/vod_opt.sh >/dev/null" >> /var/spool/cron/root
grep "origin.sh" /var/spool/cron/root || echo "*/5 * * * * bash /server/scripts/origin.sh >/server/scripts/versionupdate.log" >> /var/spool/cron/root
